package main

import (
	"database/sql"
	"fmt"

	_ "github.com/go-sql-driver/mysql"
)

var (
	dbhostsip  = "127.0.0.1:3306" //IP地址
	dbusername = "root"           //用户名
	dbpassword = "zhuqiyun123"    //密码
	dbname     = "goiot"          //数据库名
)

func iot_db() {

	db, err := sql.Open("mysql", "root:zhuqiyun123@tcp(127.0.0.1:3306)/goiot?charset=utf8")
	checkErr(err)
	//插入数据
	stmt, err := db.Prepare("INSERT userinfo SET username=?,departname=?,created=?")
	checkErr(err)

	res, err := stmt.Exec("zhuqiyun", "tec", "2016-03-06")
	checkErr(err)

	id, err := res.LastInsertId()
	checkErr(err)

	fmt.Println("id============================%d", id)
}
func checkErr(err error) {
	if err != nil {
		fmt.Println("err============================%s", err)
		panic(err)
	}
	fmt.Println("OK\n")
}
